<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增检测')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-ncCheck-add">
        <input id="status" name="status" value="3" type="hidden">
        <!--创建菜房订单-->

        <input id="treeId" name="cropVarieties" type="hidden" value="100"/>
        <input id="cforderType" name="cforderType" type="hidden" value="1">

        <div class="form-group">
            <label class="col-sm-3 control-label">菜房：</label>
            <div class="col-sm-8">
                <select id="cforderFor" name="cforderFor" required class="form-control m-b">
                    <option value="1">菜房1</option>
                    <option value="2">菜房2</option>
                </select>
            </div>
        </div>

        <!--<div class="form-group">
            <label class="col-sm-3 control-label">检测类型：</label>
            <div class="col-sm-8">
                <select name="cforderType" required class="form-control m-b"
                        th:with="type=${@dict.getType('cforderType')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>-->


        <div class="form-group">
            <label class="col-sm-3 control-label">作物品种：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" name="cropVarietiesCn" type="text" required onclick="selectCaiTree()"
                           id="treeName" readonly="true">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>

        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">计划编号：</label>
            <div class="col-sm-8">
                <select id="planId" name="planId" class="form-control">
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">抑制率(%)：</label>
            <div class="col-sm-8">
                <input id="yzl" name="yzl" required class="form-control" type="text">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">检测结果：</label>
            <div class="col-sm-8">
                <select name="checkResult" required class="form-control m-b"
                        th:with="type=${@dict.getType('check_result')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">检测时间：</label>
            <div class="col-sm-8">
                <input id="checkTime" data-format="yyyy-MM-dd HH:mm:ss" name="checkTime" required
                       th:value="*{#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd hh:mm:ss')}"
                       class="form-control"
                       type="text" th:class="time-input">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea id="remark" rows="4" name="remark" class="form-control" type="text"></textarea>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "system/ncCheck"
    var cai_prefix = ctx + "system/cai";
    $("#form-ncCheck-add").validate({
        rules: {
            xxxx: {
                required: true,
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        $('#cforderType').val($('#cforderFor').val());

        if ($.validate.form()) {
            $.operate.save(prefix + "/addCheck", $('#form-ncCheck-add').serialize(),function () {
              /*  parent.reload();*/
                $.modal.closeLoading();
                $.modal.enable();
            $.modal.msgSuccess("添加成功！");
                parent.$('#bootstrap-table').bootstrapTable('refresh', {
                    silent: true
                });
                parent.$('#bootstrap-table-1').bootstrapTable('refresh', {
                    silent: true
                });
            },1);

        }
    }

    /*蔬菜管理-新增-选择父蔬菜树*/
    function selectCaiTree() {
        var options = {
            title: '蔬菜选择',
            width: "380",
            url: cai_prefix + "/selectCaiTree/" + $("#treeId").val() + '?parentIds=210,',
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
            getPlans();
        }

    }

    function getPlans() {
        var url = ctx + 'system/ncZhibao/zhibaoPlanList?type=2';
        var treeId = $("#treeId").val();
        myPost(url, {treeId: treeId},
            function (data) {
                var str = '';
                $("#planId").html('');
                if (data.code == 0) {
                    if (data.rows.length == 0) {
                        $.modal.msgWarning("没有正在执行的计划！");
                    }
                    else {
                        for (var i = 0; i < data.rows.length; i++) {
                            var obj = data.rows[i];
                            str += '<option value="' + obj.planId + '">(' + obj.planCode+')-'+obj.teamCn + '-' + obj.cropNameCn + '-' + obj.cropVarietiesCn + '-' + dateFtt(obj.planTime) + '</option>';
                        }
                        $("#planId").html(str);
                    }

                }
            }, function (e) {
                layer.msg(e.msg);
            })
    }
</script>
</body>
</html>
